package com.example.wengwyue.patientapplication.Session;

import android.content.Context;

import com.example.wengwyue.patientapplication.controller.ActivityController;
import com.hospital.common.api.UserEntityKeeper;


/**
 * 作者： wengwyue   时间： 16/8/5.
 * 功能：
 * 修改：
 */
public class Session {
    private static Session session = null;

    public static Session instance() {
        if (session != null) {
            return session;
        }

        return new Session();
    }

    protected  SessionCallback mSessionCallback;
    public void startNarmolLogin(Context context, SessionCallback callback) {
        mSessionCallback = callback;
        if (isLogin()) {
            sessionCallback();
        } else {
            ActivityController.goToLogin(context);
        }
    }
    public boolean isLogin() {
            if (UserEntityKeeper.readAccessToken().key != null) {
                return true;
            }
        return false;
    }

    private void sessionCallback() {
        if (mSessionCallback != null) {
            mSessionCallback.callback(UserEntityKeeper.readAccessToken());
            mSessionCallback = null;
        }
    }
}
